from conan import ConanFile
from conan.tools.cmake import CMakeToolchain, CMake, cmake_layout
from conan.tools.files import get
from conan.tools.env import Environment

class VsomeipRecipe(ConanFile):
    name = "vsomeip"
    version = "3.4.10"  
    license = "MPL-2.0"
    author = "Bayerische Motoren Werke Aktiengesellschaft (BMW AG)"
    url = "https://github.com/COVESA/vsomeip"
    description = ("The vsomeip stack implements the Scalable service-Oriented MiddlewarE over IP (SOME/IP) protocol.")
    topics = ("SOME/IP", "service-discovery", "automotive", "vsomeip")
    # Binary configuration
    settings = "os", "compiler", "build_type", "arch"
    options = {"shared": [True, False], "fPIC": [True, False]}
    default_options = {"shared": False, "fPIC": True}

    def source(self):
        # Please, be aware that using the head of the branch instead of an immutable tag
        # or commit is a bad practice and not allowed by Conan
        get(self, "https://github.com/COVESA/vsomeip/archive/refs/tags/3.4.10.zip",
                  strip_root=True)

    def requirements(self):
        self.requires("boost/1.84.0")

    def config_options(self):
        if self.settings.os == "Windows":
            del self.options.fPIC

    def layout(self):
        cmake_layout(self)

    def generate(self):
        env = Environment()
        env.define("BOOST_ROOT", "/home/third_party/arm32/boost") #交叉编译环境下,指定编译好的boost库的路径
        envvars = env.vars(self)
        envvars.save_script("conanbuildenv")
        tc = CMakeToolchain(self)
        tc.generate()

    def build(self):
        cmake = CMake(self)
        cmake.configure()
        cmake.build()

    def package(self):
        cmake = CMake(self)
        cmake.install()

    def package_info(self):
        self.cpp_info.libs = ["vsomeip"]